package com.seselin.joke.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.seselin.joke.R;
import com.seselin.joke.http.JokeBean;

import java.util.ArrayList;
import java.util.List;


public class SimpleTextAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private List<JokeBean.ResultBean.DataBean> dataList = new ArrayList<>();

    public SimpleTextAdapter(Context context) {
        inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public void initData(List<JokeBean.ResultBean.DataBean> dataList) {
        this.dataList = dataList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.simple_text_item, parent, false);
            holder.textView = (TextView) convertView.findViewById(R.id.textView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.textView.setText(dataList.get(position).getContent());

        return convertView;
    }

    public static class ViewHolder {
        public TextView textView;
    }

}
